package com.main.util.template;

import java.io.File;
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import freemarker.template.Configuration;

public class TemplateUtil {
	
	 private static  Logger log=LoggerFactory.getLogger(TemplateUtil.class);
	 
	 private static TemplateUtil tu;
	 private  Configuration cfg;            //模版配置对象 
	 
     private TemplateUtil(){}
     
     /**
      * 单利获取配置文件
      * @return
      */
     public static TemplateUtil getTemplateUtil(){
    	 if(tu==null){
    		 String path=TemplateUtil.class.getResource("/").toString().substring(6)+"template/";
    		 tu=new TemplateUtil();
    		 tu.cfg = new Configuration(Configuration.VERSION_2_3_25); 
    		 //设置FreeMarker的模版文件夹位置 
    		 try {
				tu.cfg.setDirectoryForTemplateLoading(new File(path));
			} catch (IOException e) {
			   log.error("加载模板文件出错",e);
			} 
    	 }    		
    		 return tu;
     }

	public  Configuration getCfg() {
		return cfg;
	}

}
